package cn.tedu.objectx;

import java.util.Objects;

public class ObjectDemo1 {
    public static void main(String[] args) throws Throwable {
//        Animal animal = new Animal();
//        animal.finalize();
//        ObjectDemo1 obj =  new ObjectDemo1();
//        obj.finalize();
//        System.out.println(obj);
//        Animal animal = new Dog();//0x001
//        System.out.println(animal);//cn.tedu.objectx.Dog@28d93b30
//        System.out.println(animal.getClass().getName());
//        Animal animal1 = new Cat();
//        System.out.println(animal1.getClass());

        //toString
//        System.out.println(new Object());//java.lang.Object@28d93b30
//        Animal animal = new Animal();
//        animal.name = "小白";
//        animal.age = 2;
//        System.out.println(animal);//cn.tedu.objectx.Animal@28d93b30
//        System.out.println(animal.name+","+animal.age);

//        User user = new User();
//        System.out.println(user.hashCode());
//        User user1 = new User();
//        System.out.println(user1.hashCode());
//        int num1 = 5;
//        int num2 = 6;
//        System.out.println(num1==num2);//false
        Animal animal = new Animal();
        animal.name = "小白";
        animal.age = 2;
        Animal animal1 = new Animal();
        animal1.name = "小白";
        animal1.age = 2;
        System.out.println(animal==animal1);//地址值是否相等 false
        System.out.println(animal.equals(animal1));//false
//        Animal animal2 = animal;
//        System.out.println(animal==animal2);//true

//        System.out.println(animal.age == animal1.age);

    }
}
class Animal{
//    Pet pet;
    String name;
    int age;
    //重写
    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                '}';
    }
}
class Dog extends Animal{}
class Cat extends Animal{}
class User{
    private String phone;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "User{" +
                "phone='" + phone + '\'' +
                '}';
    }

}
